package hai.com.android_test.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

import butterknife.ButterKnife;
import hai.com.android_test.R;
import hai.com.android_test.utils.HttpUtils;

public class HttpActivity extends AppCompatActivity {
    String logapp = "https://mportal.tianjihuifu.com/tjhf/loginRegist/login?uname=13265468238&pwd=123456";
    String logOutapp = "https://mportal.tianjihuifu.com/tjhf/loginRegist/logout";
    String logwx = "https://wx.tianjihuifu.com/tjhf/loginRegist/mobile/login?userName=13265468238&userPwd=123456";
    String logOutwx = "https://wx.tianjihuifu.com/tjhf/loginRegist/logoutApp";
    String getInfo = "https://mportal.tianjihuifu.com/tjhf/myAccount/getAccountAssetInfo";//需要登陆
    String wxuri = "https://wx.tianjihuifu.com/topic/activity/20160516/index.html";//需要登陆
    String uri_test = "https://wx.tianjihuifu.com/topic/find/index.html";
    String uri_jxq = "http://t.cn/RIpIR59";
    String protocol="https://mportal.tianjihuifu.com/projects/contract2.html";
    String uri = "http://192.168.1.108:8080/webtest/jsp/imgPick.jsp";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_http);
        ButterKnife.bind(this);
    }

    public void click(View v) {
        switch (v.getId()) {
            case R.id.button:
                get(logapp);
                break;
            case R.id.button2:
                post(logwx);
                break;
            case R.id.button3:
                get(getInfo);
                break;
            case R.id.button4:
                Intent intent = new Intent(getApplicationContext(), WebViewActivity.class);
                intent.putExtra("uri", uri);
                startActivity(intent);
                break;
            case R.id.button5:
                get(logOutapp);
                break;
            case R.id.button6:
                get(logOutwx);
                break;
        }
    }

    private void get(final String uri) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                HttpUtils.get(uri);
            }
        }).start();
    }

    private void post(final String uri) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                HttpUtils.post(uri, null);
            }
        }).start();
    }
    void testHttpUrlConnection(String uri){
        try {
            URL url = new URL(uri);
            URLConnection urlConnection = url.openConnection();
            urlConnection.connect();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
